﻿@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.CurrentCarts").Text;
}

@Html.AntiForgeryToken()
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-sales.png")" alt="" />
        @T("Admin.CurrentCarts")
    </div>
    <div class="options">
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            <div id="carts-grid"></div>

            <script>
    $(document).ready(function() {
        $("#carts-grid").kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("CurrentCarts", "ShoppingCart"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(defaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(gridPageSizes)]
            },
            //details grid
            detailInit: detailInit,
            scrollable: false,
            columns: [
                {
                    field: "CustomerId",
                    title: "@T("Admin.CurrentCarts.Customer")",
                    template: '<a href="@Url.Content("~/Admin/Customer/Edit/")#=CustomerId#">#:CustomerEmail#</a>'
                }, {
                    field: "TotalItems",
                    title: "@T("Admin.CurrentCarts.TotalItems")",
                    width: 150
                }
            ]
        });
    });

    //details grid
    function detailInit(e) {
        $("<div/>").appendTo(e.detailCell).kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("GetCartDetails", "ShoppingCart"))?customerId="+e.data.CustomerId,
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            scrollable: false,
            sortable: true,
            pageable: {
                refresh: true,
                numeric: false,
                previousNext: false,
                info: false
            },
            columns: [
                {
                    field: "ProductName",
                    title: "@T("Admin.CurrentCarts.Product")",
                    template: '<a href="@Url.Content("~/Admin/Product/Edit/")#=ProductId#">#:ProductName#</a>' +
                        '# if(AttributeInfo && AttributeInfo.length > 0) {# <br />#=AttributeInfo# #} #',
                    width: 400
                },{
                    field: "Quantity",
                    title: "@T("Admin.CurrentCarts.Quantity")",
                    width: 150
                },{
                    field: "UnitPrice",
                    title: "@T("Admin.CurrentCarts.UnitPrice")",
                    width: 150
                },{
                    field: "Total",
                    title: "@T("Admin.CurrentCarts.Total")",
                    width: 150
                },{
                    field: "Store",
                    title: "@T("Admin.CurrentCarts.Store")",
                    width: 150
                },{
                    field: "UpdatedOn",
                    title: "@T("Admin.CurrentCarts.UpdatedOn")",
                    width: 150,
                    type: "date",
                    format: "{0:G}"
                }
            ]
        });
    }
            </script>
        </td>
    </tr>
</table>